package com.fubowen.lepton.ui.container.children.bookmark.recycler

import androidx.recyclerview.widget.SortedListAdapterCallback
import com.fubowen.lepton.bean.BookmarkBean

class BookmarkSortedListAdapterCallback(adapter: BookmarkAdapter) :
    SortedListAdapterCallback<BookmarkBean>(adapter) {

    override fun compare(prev: BookmarkBean?, next: BookmarkBean?): Int {
        if (prev == null || next == null) {
            return 0
        }
        val comparator = compareBy<BookmarkBean> { it.topping }.thenBy { it.timestamp }.reversed()
        return comparator.compare(prev, next)
    }

    override fun areContentsTheSame(oldItem: BookmarkBean?, newItem: BookmarkBean?): Boolean {
        return oldItem == newItem
    }

    override fun areItemsTheSame(oldItem: BookmarkBean?, newItem: BookmarkBean?): Boolean {
        return oldItem?.url == newItem?.url
    }
}